// pages/toif/toif.js
Page({

  data: {
    id:"",
    list:[]

  },
  onLoad: function (options) {
    this.setData({
      id:options.id
    })
    wx.request({
      url: 'https://www.uinav.com/api/public/v1/goods/detail?goods_id='+options.id,
      success:res=>{
        console.log(res.data.message);
        this.setData({
          list:res.data.message
        })
      }
    })
  },
  oppd(){
    let arr= wx.getStorageSync('go')||[]
    let index=arr.findIndex(item=>{
      return item.id==this.data.id
    })
    if(index>-1){
      arr[index].num++
    }else{
      let obj={
        id:this.data.list.goods_id,
        name:this.data.list.goods_name,
        price:this.data.list.goods_price,
        img:this.data.list.goods_small_logo,
        num:1,
        checkbox:true,
      }
      arr.push(obj)
    }
    wx.setStorageSync('go',arr)
    wx.showToast({
      title: '加入购物车',
    })
    
  },
  tolist(){
    wx.switchTab({
      url: '/pages/list/list',
    })
  }

 
})